﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhomble.Data.Projects;

namespace Rhomble.Services.Projects
{
	public class ProjectService
	{
		private ProjectRepository _repo;
		private string _userName;

		public ProjectService(string userName)
		{
			_repo = new ProjectRepository(userName);
			_userName = userName;
		}

		public IList<ProjectModel> GetAll()
		{
			var Projects = _repo.GetQuery()
							.DefaultOrder()
							.Select(ProjectTransforms.EntityToModel)
							.ToList();

			return Projects;
		}

		public ProjectModel GetByID(Guid ProjectID)
		{
			var Project = _repo.GetQuery()
							.WithID(ProjectID)
							.Select(ProjectTransforms.EntityToModel)
							.Single();

			return Project;
		}

		public void AddNew(ProjectModel model)
		{
			var entity = ProjectTransforms.ModelToEntity(model);
			_repo.AddNew(entity);
		}

		public void Update(Guid ProjectID, ProjectModel model)
		{
			var entity = ProjectTransforms.ModelToEntity(model);
			_repo.Update(ProjectID, entity);
		}
	}
}
